package com.gitee.feizns.explore.data_structure.graph;

import com.gitee.feizns.explore.data_structure.tree.bs.easy.TreeNode;

import java.util.LinkedList;
import java.util.Queue;
import java.util.TreeMap;

/**
 * 1161. 最大层内元素和
 * @author feizns
 * @since 2020/4/30
 */
public class MaxLevelSum {

//    public int maxLevelSum(TreeNode root) {
//        TreeMap<Integer, Integer> treeMap = new TreeMap<>();
//        Queue<TreeNode> queue = new LinkedList<>();
//        queue.add(root);
//        int level = 1;
//        while ( !queue.isEmpty() ) {
//            int size = queue.size();
//            int sum = 0;
//            for (int i = 0; i < size; i++) {
//                TreeNode cur = queue.remove();
//                sum += cur.val;
//                if ( cur.left != null )
//                    queue.add(cur.left);
//                if ( cur.right != null )
//                    queue.add(cur.right);
//            }
//            treeMap.put(sum, level);
//            level++;
//        }
//        return treeMap.lastEntry().getValue();
//    }

    public static int aMethod(int i)throws Exception
    {
        try{
            return i / 10;
        }
        catch (Exception ex)
        {
            System.out.println("E");
            throw new Exception("exception in a Method");
        } finally{
            System.out.printf("finally");
        }
    }

    public static void main(String [] args)
    {
        try
        {
            aMethod(0);
        }
        catch (Exception ex)
        {
            System.out.printf("exception in main");
        }
        System.out.printf("finished");
    }

}
